package com.ruoyi.system.mapper;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;
import com.ruoyi.system.domain.Transactionrecords;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 交易记录Mapper接口
 * 
 * @author yy
 * @date 2024-08-13
 */
public interface TransactionrecordsMapper 
{
    /**
     * 查询交易记录
     * 
     * @param trid 交易记录主键
     * @return 交易记录
     */
    public Transactionrecords selectTransactionrecordsByTrid(Long trid);

    /**
     * 查询交易记录列表
     * 
     * @param transactionrecords 交易记录
     * @return 交易记录集合
     */
    public List<Transactionrecords> selectTransactionrecordsList(Transactionrecords transactionrecords);

    /**
     * 新增交易记录
     * 
     * @param transactionrecords 交易记录
     * @return 结果
     */
    public int insertTransactionrecords(Transactionrecords transactionrecords);

    /**
     * 修改交易记录
     * 
     * @param transactionrecords 交易记录
     * @return 结果
     */
    public int updateTransactionrecords(Transactionrecords transactionrecords);

    /**
     * 删除交易记录
     * 
     * @param trid 交易记录主键
     * @return 结果
     */
    public int deleteTransactionrecordsByTrid(Long trid);

    /**
     * 批量删除交易记录
     * 
     * @param trids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteTransactionrecordsByTrids(Long[] trids);

    @Select("SELECT COALESCE(SUM(charge_capacity), 0) FROM tb_transactionrecords WHERE tr_kinds = #{kind} AND Date(tr_time) = #{date}")
    BigDecimal sumChargeCapacityByKindAndDate(@Param("kind") String kind, @Param("date") LocalDate date);

    @Select("SELECT COALESCE(COUNT(*), 0) FROM tb_transactionrecords WHERE tr_kinds = #{kind} AND Date(tr_time) = #{date}")
    int countTransactionsByKindAndDate(@Param("kind") String kind, @Param("date") LocalDate date);
}
